package sanrenxing.dayEnd.backRepertoryTotal.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    //拦截器对象
    @Autowired
    MyInterceptor myInterceptor;

    //定义一个拦截路径
    String[] crudOperation={
            "/**"
            //"/uc/warning"
    };

    //定义一个不拦截的路径:登陆路径 修改密码
    String[] notInterceptor= {
            "/uc/signin",
            "/uc/warning"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //将拦截器注入
        InterceptorRegistration interceptor = registry.addInterceptor(myInterceptor);
        //将需要拦截的路径注入
        interceptor.addPathPatterns(crudOperation);
        //将不需要拦截的路径注入
        interceptor.excludePathPatterns(notInterceptor);
    }
}
